package com.itheima.service.impl;

import com.itheima.domain.CategoryExample;
import com.itheima.domain.Comment;
import com.itheima.domain.CommentExample;
import com.itheima.mapper.CommentMapper;
import com.itheima.mapper.MoviesMapper;
import com.itheima.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    CommentMapper commentMapper;

    @Autowired
    MoviesMapper moviesMapper;
    @Override
    public List<Comment> findByComment(Integer id) {

        //创建条将查询对象
        CommentExample commentExample = new CommentExample();
        // 按评论时间进行升序
        commentExample.setOrderByClause("time desc");
        //基于电影id进行条件查询
        CommentExample.Criteria criteria = commentExample.createCriteria().andMoviesIdEqualTo(id);
        // 基于电影的条将进行的查询
        List<Comment> comments = commentMapper.selectByExample(commentExample);
        return comments;
    }

    @Override
    public void saveComment(Comment comment) {
        commentMapper.insertSelective(comment);
    }
}
